<!--
    Author : Gisca
    Controller dari Mengubah Data Diri Pengguna
-->

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include 'page/abstractPage.php';

class ServerMengubahDataDiriPribadi extends AbstractPage {

    private $action='';
    private $message='';
    //private $tabelPengguna='';
    //private $tabelDataPengguna='';
    //private $userid='';
    private $usernameEdit='';
    private $nameEdit='';
    private $passwordEdit='';
    private $emailEdit='';
    private $genderEdit='';
    private $addressEdit='';
    private $telpEdit='';

    public function ServerMengubahDataDiriPribadi()
    {
        parent::__construct();
        $this->load->model('Pengguna');

        //membuat template tabel
        $tmpl = array (
                    'table_open'          => '<table border="1" cellpadding="4" cellspacing="0" class="table1">',

                    'heading_row_start'   => '<tr>',
                    'heading_row_end'     => '</tr>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>',

                    'row_start'           => '<tr>',
                    'row_end'             => '</tr>',
                    'cell_start'          => '<td>',
                    'cell_end'            => '</td>',

                    'row_alt_start'       => '<tr>',
                    'row_alt_end'         => '</tr>',
                    'cell_alt_start'      => '<td>',
                    'cell_alt_end'        => '</td>',

                    'table_close'         => '</table>'
              );
        $this->table->set_template($tmpl);
    }

    public function editDataDiriPribadi($user_id)
    {
        $this->load->model('Pengguna','pengguna');
        $this->action="editDataDiriPribadi";
        $this->usernameEdit = $user_id;
        //query
        $pengguna = $this->Pengguna->getDataPengguna($user_id);

        $this->nameEdit = $pengguna->name;
        $this->passwordEdit = $pengguna->password;
        $this->emailEdit = $pengguna->email;
        $this->genderEdit = $pengguna->gender;
        $this->addressEdit = $pengguna->address;
        $this->telpEdit = $pengguna->telephone;
        
        $this->index();
    }

    public function simpanEditPengguna()
    {
        $this->load->model('Pengguna','pengguna');
        $this->pengguna->updatePengguna($_POST['user_id'],$_POST['name'],$_POST['password'],$_POST['email'],$_POST['gender'],$_POST['address'],$_POST['telp']);
        $this->message='Perubahan Data Pengguna Sukses';
        redirect('/');
    }

    public function redirectHome()
    {
        redirect('/');
    }
    
    function _buildContent()
    {
        if ($this->action=='editDataDiriPribadi')
        {
             $data = array (
                'user_id' => $this->usernameEdit,
                'usernameEdit' => $this->usernameEdit,
                'nameEdit' => $this->nameEdit,
                'passwordEdit' => $this->passwordEdit,
                'emailEdit' => $this->emailEdit,
                'genderEdit' => $this->genderEdit,
                'addressEdit'=> $this->addressEdit,
                'telpEdit' => $this->telpEdit
            );
            $this->load->view('MengubahDataDiriPribadi/editDataDiriPribadi',$data);
        }
    }
 
}
